package com.cakin.javademo;

/**
 * @ClassName: ArraryDemo1
 * @Description: 数组测试
 * @Date: 2020/6/16
 * @Author: cakin
 */
public class ArraryDemo1 {
    public static void main(String[] args) {
        int[] a = {1, 3, 6, 8, 2, 4, 56, 87, 54};
        // 打印所有数组元素
        for (int i = 0; i < a.length; i++) {
            System.out.println("a[" + i + "]=" + a[i]);
        }
        for (int item : a) {
            System.out.println(item);
        }
        // 计算所有元素的总和
        int sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum = sum + a[i];
        }
        System.out.println("sum=" + sum);
        // 查找最大元素
        int max = a[0];
        for (int i = 1; i < a.length; i++) {
            if (a[i] > max) {
                max = a[i];
            }
        }
        System.out.println("最大值为" + max);

    }
}
